package com.example.administrator.activity.boradcast.help;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.administrator.activity.R;

public class HelpActivity extends AppCompatActivity implements View.OnClickListener {
    /**
     * 界面（广播发送者）：发送广播
     * 注册
     * @param savedInstanceState
     */
    Button btn;
    MyReceiver2 myReceiver2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        btn=findViewById(R.id.ch5_help_btn);
        btn.setOnClickListener(this);
        myReceiver2=new MyReceiver2();
    }

    @Override
    public void onClick(View v) {
        /*
        按钮点击事件：发送广播
         */
        Intent intent=new Intent();
        intent.setAction("com.example.help");
        sendBroadcast(intent);

    }

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter filter=new IntentFilter();
        filter.addAction("com.example.help");
        registerReceiver(myReceiver2,filter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(myReceiver2);
    }
}
